package com.terabits.smartriver.controller;

import com.terabits.smartriver.constants.result.BaseResp;
import com.terabits.smartriver.constants.result.ResultStatus;
import com.terabits.smartriver.meta.po.Project;
import com.terabits.smartriver.meta.po.ProjectMaterial;
import com.terabits.smartriver.meta.po.ProjectTask;
import com.terabits.smartriver.service.ProjectService;
import com.terabits.smartriver.util.PageData;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
public class ProjectController extends BaseController {
    @Autowired
    private ProjectService projectService;

    @ApiOperation(value = "查询 项目", tags = {"项目管理"})
    @RequestMapping(value = "/project-mgt/project/get", method = RequestMethod.GET)
    public BaseResp getProject() {
        return new BaseResp(ResultStatus.SUCCESS, projectService.getProject(this.getPageData()));
    }

    @ApiOperation(value = "添加 项目", tags = {"项目管理"}, notes = "添加 项目")
    @RequestMapping(value = "/project-mgt/project/add", method = RequestMethod.POST)
    public BaseResp addProject(Project project) {
        int addRes = projectService.addProject(project);
        if (addRes == -1) {
            return new BaseResp(ResultStatus.error_duplicated_data);
        }
        if (project.getId() != null) {
            return new BaseResp(ResultStatus.SUCCESS);
        }

        return new BaseResp(ResultStatus.FAIL);
    }

    @ApiOperation(value = "修改 项目", tags = {"项目管理"})
    @RequestMapping(value = "/project-mgt/project/update", method = RequestMethod.POST)
    public BaseResp updateProject(Project project) {
        return new BaseResp(ResultStatus.SUCCESS, projectService.updateProject(project));
    }

    @ApiOperation(value = "删除 项目", tags = {"项目管理"})
    @RequestMapping(value = "/project-mgt/project/delete", method = RequestMethod.POST)
    public BaseResp deleteProject(Integer id) {
        int res = projectService.deleteProject(id);
        if (res == -1) {
            return new BaseResp(ResultStatus.error_delete_failed);
        }
        return new BaseResp(ResultStatus.SUCCESS, res);
    }

    @ApiOperation(value = "添加 项目资料", tags = {"项目管理"})
    @RequestMapping(value = "/project-mgt/project/material/add", method = RequestMethod.POST)
    public BaseResp addProjectMaterial(ProjectMaterial projectMaterial) {
        projectService.addProjectMaterial(projectMaterial);
        return new BaseResp(ResultStatus.SUCCESS);
    }

    @ApiOperation(value = "查看 项目资料", tags = {"项目管理"})
    @RequestMapping(value = "/project-mgt/project/material/get", method = RequestMethod.GET)
    public BaseResp getProjectMaterial(ProjectMaterial projectMaterial) {
        return new BaseResp(ResultStatus.SUCCESS, projectService.getProjectMaterial(projectMaterial));
    }

    @ApiOperation(value = "删除 项目资料", tags = {"项目管理"})
    @RequestMapping(value = "/project-mgt/project/material/delete", method = RequestMethod.POST)
    public BaseResp deleteProjectMaterial(ProjectMaterial projectMaterial) {
        Integer integer = projectService.deleteProjectMaterial(projectMaterial);
        if (integer <= 0) {
            new BaseResp(ResultStatus.error_delete_failed);
        }
        return new BaseResp(ResultStatus.SUCCESS,projectMaterial.getId());
    }

    @ApiOperation(value = "查看 进度安排", tags = {"项目管理-进度安排"})
    @RequestMapping(value = "/project-mgt/schedule/get", method = RequestMethod.GET)
    public BaseResp getProjectSchedule() {
        List<PageData> schedule = projectService.getProjectSchedule(this.getPageData());
        return new BaseResp(ResultStatus.SUCCESS, schedule);
    }

    @ApiOperation(value = "查看 任务", tags = {"项目管理-任务管理"})
    @RequestMapping(value = "/project-mgt/task/get", method = RequestMethod.GET)
    public BaseResp getProjectTask() {
        return new BaseResp(ResultStatus.SUCCESS, projectService.getProjectTask(this.getPageData()));
    }

    @ApiOperation(value = "新增 任务", tags = {"项目管理-任务管理"})
    @RequestMapping(value = "/project-mgt/task/add", method = RequestMethod.POST)
    public BaseResp addProjectTask(ProjectTask projectTask) {
        return new BaseResp(ResultStatus.SUCCESS, projectService.addProjectTask(projectTask));
    }

    @ApiOperation(value = "修改 任务", tags = {"项目管理-任务管理"})
    @RequestMapping(value = "/project-mgt/task/update", method = RequestMethod.POST)
    public BaseResp updateTask(ProjectTask projectTask) {
        return new BaseResp(ResultStatus.SUCCESS, projectService.updateProjectTask(projectTask));
    }

    @ApiOperation(value = "查找 验收", tags = {"项目管理-设备验收"})
    @RequestMapping(value = "/project-mgt/acceptance/get", method = RequestMethod.GET)
    public BaseResp getProjectAcceptance() {
        return new BaseResp(ResultStatus.SUCCESS, projectService.getProjectAcceptance(this.getPageData()));
    }
}
